<template>
	<el-dialog class="dialog" :title="dialogTitle" :visible.sync="showCheckPassWin" :width="checkType == 'change' ? '650px' : '480px'" :lock-scroll="false" :before-close="handleCheckPassWinClose">
		<div style="text-align: right;">
			<el-button style="text-align: right;" type="text" size="medium" @click="checkAll">一键全部确认</el-button>
		</div>
		<el-form :model="checkForm" ref="checkForm" label-width="220px" size="small" label-suffix=": ">
			<template v-if="checkType == 'put'">
				<el-form-item prop="equipmentLabels" label="设备标签是否合规" required>
					<el-switch v-model="checkForm.equipmentLabels" active-color="RGBA(33, 183, 149, 1)" active-value="1" inactive-value="0" inactive-color="RGBA(204, 204, 204, 1)"> </el-switch>
				</el-form-item>
				<el-form-item prop="powerLineLabels" label="电源线标签是否合规" required>
					<el-switch v-model="checkForm.powerLineLabels" active-color="RGBA(33, 183, 149, 1)" active-value="1" inactive-value="0" inactive-color="RGBA(204, 204, 204, 1)"> </el-switch>
				</el-form-item>
				<el-form-item prop="netLineLabels" label="网线标签是否合规" required>
					<el-switch v-model="checkForm.netLineLabels" active-color="RGBA(33, 183, 149, 1)" active-value="1" inactive-value="0" inactive-color="RGBA(204, 204, 204, 1)"> </el-switch>
				</el-form-item>
				<el-form-item prop="opticalFiberLabels" label="光纤标签是否合规" required>
					<el-switch v-model="checkForm.opticalFiberLabels" active-color="RGBA(33, 183, 149, 1)" active-value="1" inactive-value="0" inactive-color="RGBA(204, 204, 204, 1)"> </el-switch>
				</el-form-item>
				<el-form-item prop="equipmentGround" label="设备是否接地" required>
					<el-switch v-model="checkForm.equipmentGround" active-color="RGBA(33, 183, 149, 1)" active-value="1" inactive-value="0" inactive-color="RGBA(204, 204, 204, 1)"> </el-switch>
				</el-form-item>
				<el-form-item prop="plugging" label="空闲端口是否物理封堵" required>
					<el-switch v-model="checkForm.plugging" active-color="RGBA(33, 183, 149, 1)" active-value="1" inactive-value="0" inactive-color="RGBA(204, 204, 204, 1)"> </el-switch>
				</el-form-item>
				<el-form-item prop="probe" label="探针是否配置" required>
					<el-switch v-model="checkForm.probe" active-color="RGBA(33, 183, 149, 1)" active-value="1" inactive-value="0" inactive-color="RGBA(204, 204, 204, 1)"> </el-switch>
				</el-form-item>
			</template>
			<template v-if="checkType == 'out'">
				<el-form-item prop="powerLineClear" label="机柜内废弃电源线是否清理" required>
					<el-switch v-model="checkForm.powerLineClear" active-color="RGBA(33, 183, 149, 1)" active-value="1" inactive-value="0" inactive-color="RGBA(204, 204, 204, 1)"> </el-switch>
				</el-form-item>
				<el-form-item prop="netLineClear" label="废弃网线是否清理" required>
					<el-switch v-model="checkForm.netLineClear" active-color="RGBA(33, 183, 149, 1)" active-value="1" inactive-value="0" inactive-color="RGBA(204, 204, 204, 1)"> </el-switch>
				</el-form-item>
				<el-form-item prop="garbageClear" label="垃圾是否清理" required>
					<el-switch v-model="checkForm.garbageClear" active-color="RGBA(33, 183, 149, 1)" active-value="1" inactive-value="0" inactive-color="RGBA(204, 204, 204, 1)"> </el-switch>
				</el-form-item>
				<el-form-item prop="oldLabelsClear" label="资产原标签是否已撕掉" required>
					<el-switch v-model="checkForm.oldLabelsClear" active-color="RGBA(33, 183, 149, 1)" active-value="1" inactive-value="0" inactive-color="RGBA(204, 204, 204, 1)"> </el-switch>
				</el-form-item>
				<el-form-item prop="inStorage" label="资产是否放入库房" required>
					<el-switch v-model="checkForm.inStorage" active-color="RGBA(33, 183, 149, 1)" active-value="1" inactive-value="0" inactive-color="RGBA(204, 204, 204, 1)"> </el-switch>
				</el-form-item>
			</template>
			<template v-if="checkType == 'scrap'">
				<el-form-item prop="powerLineClear" label="机柜内废弃电源线是否清理" required>
					<el-switch v-model="checkForm.powerLineClear" active-color="RGBA(33, 183, 149, 1)" active-value="1" inactive-value="0" inactive-color="RGBA(204, 204, 204, 1)"> </el-switch>
				</el-form-item>
				<el-form-item prop="netLineClear" label="废弃网线是否清理" required>
					<el-switch v-model="checkForm.netLineClear" active-color="RGBA(33, 183, 149, 1)" active-value="1" inactive-value="0" inactive-color="RGBA(204, 204, 204, 1)"> </el-switch>
				</el-form-item>
				<el-form-item prop="garbageClear" label="垃圾是否清理" required>
					<el-switch v-model="checkForm.garbageClear" active-color="RGBA(33, 183, 149, 1)" active-value="1" inactive-value="0" inactive-color="RGBA(204, 204, 204, 1)"> </el-switch>
				</el-form-item>
				<el-form-item prop="oldLabelsClear" label="资产原标签是否已撕掉" required>
					<el-switch v-model="checkForm.oldLabelsClear" active-color="RGBA(33, 183, 149, 1)" active-value="1" inactive-value="0" inactive-color="RGBA(204, 204, 204, 1)"> </el-switch>
				</el-form-item>
				<!-- <el-form-item prop="inStorage" label="资产是否放入库房" required>
					<el-switch v-model="checkForm.inStorage" active-color="RGBA(33, 183, 149, 1)" active-value="1" inactive-value="0" inactive-color="RGBA(204, 204, 204, 1)"> </el-switch>
				</el-form-item> -->
			</template>
			<template v-if="checkType == 'change'">
				<el-row :gutter="10">
					<el-col :span="12" :offset="0">
						<div>上架验收项：</div>
						<el-form-item prop="equipmentLabels" label="设备标签是否合规" required>
							<el-switch v-model="checkForm.equipmentLabels" active-color="RGBA(33, 183, 149, 1)" active-value="1" inactive-value="0" inactive-color="RGBA(204, 204, 204, 1)"> </el-switch>
						</el-form-item>
						<el-form-item prop="powerLineLabels" label="电源线标签是否合规" required>
							<el-switch v-model="checkForm.powerLineLabels" active-color="RGBA(33, 183, 149, 1)" active-value="1" inactive-value="0" inactive-color="RGBA(204, 204, 204, 1)"> </el-switch>
						</el-form-item>
						<el-form-item prop="netLineLabels" label="网线标签是否合规" required>
							<el-switch v-model="checkForm.netLineLabels" active-color="RGBA(33, 183, 149, 1)" active-value="1" inactive-value="0" inactive-color="RGBA(204, 204, 204, 1)"> </el-switch>
						</el-form-item>
						<el-form-item prop="opticalFiberLabels" label="光纤标签是否合规" required>
							<el-switch v-model="checkForm.opticalFiberLabels" active-color="RGBA(33, 183, 149, 1)" active-value="1" inactive-value="0" inactive-color="RGBA(204, 204, 204, 1)"> </el-switch>
						</el-form-item>
						<el-form-item prop="equipmentGround" label="设备是否接地" required>
							<el-switch v-model="checkForm.equipmentGround" active-color="RGBA(33, 183, 149, 1)" active-value="1" inactive-value="0" inactive-color="RGBA(204, 204, 204, 1)"> </el-switch>
						</el-form-item>
						<el-form-item prop="plugging" label="空闲端口是否物理封堵" required>
							<el-switch v-model="checkForm.plugging" active-color="RGBA(33, 183, 149, 1)" active-value="1" inactive-value="0" inactive-color="RGBA(204, 204, 204, 1)"> </el-switch>
						</el-form-item>
						<el-form-item prop="probe" label="探针是否配置" required>
							<el-switch v-model="checkForm.probe" active-color="RGBA(33, 183, 149, 1)" active-value="1" inactive-value="0" inactive-color="RGBA(204, 204, 204, 1)"> </el-switch>
						</el-form-item>
						<el-form-item prop="probe" label="是否双网接入" required>
							<el-switch v-model="checkForm.dualNetworkAccess" active-color="RGBA(33, 183, 149, 1)" active-value="1" inactive-value="0" inactive-color="RGBA(204, 204, 204, 1)"> </el-switch>
						</el-form-item>
					</el-col>
					<el-col :span="12" :offset="0">
						<div>下架验收项：</div>
						<el-form-item prop="powerLineClear" label="机柜内废弃电源线是否清理" required>
							<el-switch v-model="checkForm.powerLineClear" active-color="RGBA(33, 183, 149, 1)" active-value="1" inactive-value="0" inactive-color="RGBA(204, 204, 204, 1)"> </el-switch>
						</el-form-item>
						<el-form-item prop="netLineClear" label="废弃网线是否清理" required>
							<el-switch v-model="checkForm.netLineClear" active-color="RGBA(33, 183, 149, 1)" active-value="1" inactive-value="0" inactive-color="RGBA(204, 204, 204, 1)"> </el-switch>
						</el-form-item>
						<el-form-item prop="garbageClear" label="垃圾是否清理" required>
							<el-switch v-model="checkForm.garbageClear" active-color="RGBA(33, 183, 149, 1)" active-value="1" inactive-value="0" inactive-color="RGBA(204, 204, 204, 1)"> </el-switch>
						</el-form-item>
						<el-form-item prop="oldLabelsClear" label="资产原标签是否已撕掉" required>
							<el-switch v-model="checkForm.oldLabelsClear" active-color="RGBA(33, 183, 149, 1)" active-value="1" inactive-value="0" inactive-color="RGBA(204, 204, 204, 1)"> </el-switch>
						</el-form-item>
					</el-col>
				</el-row>
			</template>
			<el-form-item prop="notes" label="备注" label-width="60px">
				<el-input type="textarea" v-model="checkForm.notes" :autosize="{ minRows: 3 }" maxlength="200" show-word-limit></el-input>
			</el-form-item>
		</el-form>
		<div slot="footer" class="dialog-footer">
			<!-- <el-button size="small" v-loading="backLoading" @click="checkBackHandler">验收驳回</el-button>
			<el-button size="small" type="primary" v-loading="passLoading" @click="onSubmitCheckPass">验收通过</el-button> -->
			<el-button size="small" v-loading="backLoading" @click="rejectHandler">验收驳回</el-button>
			<el-button size="small" type="primary" v-loading="passLoading" @click="passHandler">验收通过</el-button>
		</div>
		<asset-flow-send
			v-if="showFlowSend"
			@close="closeFlowSend"
			:checkConfirmInfo="checkForm"
			:checkType="checkFlowType"
			@ok="FlowSendsave"
			:instNodeId="instNodeId"
			:sendtype="sendtype"
			:wfUrl="wfUrlObj"
		></asset-flow-send>
	</el-dialog>
</template>

<script>
	import assetFlowMixin from '@/mixins/assetFlowMixin'
	import assetPutawayApi from '@/api/assetPutawayApi'
	import assetOutApi from '@/api/assetOutApi'
	import assetScrapApi from '@/api/assetScrapApi'
	import { getAction, postAction } from '@/utils/httpUtil'
	export default {
		name: 'CheckPassWin',
		mixins: [assetFlowMixin],
		props: {
			checkData: {
				type: Object,
				default: () => {
					return {}
				},
			},
			dataId: '',
			showWin: {
				type: Boolean,
				default: false,
			},
			checkType: {
				type: String,
				default: 'put', // pass: 上架，out: 下架, scrap: 报废, change: 变更
			},
			dialogTitle: '',
		},
		computed: {
			checkPass() {
				let url = ''
				switch (this.checkType) {
					case 'put':
						url = assetPutawayApi.putCheckPass
						break
					case 'out':
						url = assetOutApi.checkPass
						break
					case 'scrap':
						url = assetScrapApi.checkPass
						break
					case 'change':
						url = assetChangeApi.checkPass
						break
					default:
						break
				}
				return url
			},
			checkBack() {
				let url = ''
				switch (this.checkType) {
					case 'put':
						url = assetPutawayApi.putCheckBack
						break
					case 'out':
						url = assetOutApi.checkBack
						break
					case 'scrap':
						url = assetScrapApi.checkBack
						break
					case 'change':
						url = assetChangeApi.checkBack
						break
					default:
						break
				}
				return url
			},
			wfUrlObj() {
				let obj = {}
				switch (this.checkType) {
					case 'put':
						obj = {
							getSendToUrl: '/assetManagePut/getSendTo',
							sendToUrl: '/assetManagePut/sendTo',
							getBackToUrl: '/assetManagePut/getBackTo',
							backToUrl: '/assetManagePut/backTo',
						}
						break
					case 'out':
						obj = {
							getSendToUrl: '/assetManageOut/getSendTo',
							sendToUrl: '/assetManageOut/sendTo',
							getBackToUrl: '/assetManageOut/getBackTo',
							backToUrl: '/assetManageOut/backTo',
						}
						break
					case 'scrap':
						obj = {
							getSendToUrl: '/assetManageCancel/getSendTo',
							sendToUrl: '/assetManageCancel/sendTo',
							getBackToUrl: '/assetManageCancel/getBackTo',
							backToUrl: '/assetManageCancel/backTo',
						}
						break
					case 'change':
						obj = {
							getSendToUrl: '/assetManageChange/getSendTo',
							sendToUrl: '/assetManageChange/sendTo',
							getBackToUrl: '/assetManageChange/getBackTo',
							backToUrl: '/assetManageChange/backTo',
						}
						break
					default:
						break
				}
				return obj
			},
		},
		watch: {
			showWin(newVal, oldVal) {
				this.showCheckPassWin = newVal
			},
		},
		data() {
			return {
				showCheckPassWin: false,
				checkForm: {
					managementId: '', // 申请单ID
					dualNetworkAccess: '0', // 是否双网接入
					equipmentGround: '0', // 设备是否接地
					equipmentLabels: '0', //设备标签是否合规
					garbageClear: '0', //垃圾是否清理
					inStorage: '0', //资产是否放入库房
					netLineClear: '0', //废弃网线是否清理
					netLineLabels: '0', //网线标签是否合规
					notes: '', //验收备注
					oldLabelsClear: '0', //资产原标签是否已撕掉
					opticalFiberLabels: '0', //光纤标签是否合规
					plugging: '0', //空闲端口是否物理封堵
					powerLineClear: '0', //机柜内废弃电源线是否清理
					powerLineLabels: '0', //电源线标签是否合规
					probe: '0', //探针是否配置
					pullOut: '0', //资产是否已从机房/库房撤走
				},
				backLoading: false,
				passLoading: false,
			}
		},
		methods: {
			checkAll() {
				if (this.checkType == 'put') {
					this.checkForm.equipmentLabels = '1'
					this.checkForm.powerLineLabels = '1'
					this.checkForm.netLineLabels = '1'
					this.checkForm.opticalFiberLabels = '1'
					this.checkForm.equipmentGround = '1'
					this.checkForm.plugging = '1'
					this.checkForm.probe = '1'
				}
				if (this.checkType == 'out') {
					this.checkForm.powerLineClear = '1'
					this.checkForm.netLineClear = '1'
					this.checkForm.garbageClear = '1'
					this.checkForm.oldLabelsClear = '1'
					this.checkForm.inStorage = '1'
				}
				if (this.checkType == 'scrap') {
					this.checkForm.powerLineClear = '1'
					this.checkForm.netLineClear = '1'
					this.checkForm.garbageClear = '1'
					this.checkForm.oldLabelsClear = '1'
				}
				if (this.checkType == 'change') {
					/**
					 * @todo
					 */
					this.checkForm.equipmentLabels = '1'
					this.checkForm.powerLineLabels = '1'
					this.checkForm.netLineLabels = '1'
					this.checkForm.opticalFiberLabels = '1'
					this.checkForm.equipmentGround = '1'
					this.checkForm.plugging = '1'
					this.checkForm.probe = '1'
					this.checkForm.dualNetworkAccess = '1'
					this.checkForm.powerLineClear = '1'
					this.checkForm.netLineClear = '1'
					this.checkForm.garbageClear = '1'
					this.checkForm.oldLabelsClear = '1'
				}
			},
			handleCheckPassWinClose() {
				this.$refs.checkForm.resetFields()
				this.$emit('update:showWin', false)
			},
			onSubmitCheckPass() {
				this.passLoading = true
				this.checkForm.managementId = this.dataId
				postAction(this.checkPass, this.checkForm, 2).then(res => {
					if (res.success) {
						this.handleCheckPassWinClose()
						this.$emit('onPass')
					}
					this.passLoading = false
				})
			},
			/**
			 * 验收驳回
			 * @param {*} row
			 */
			checkBackHandler() {
				this.backLoading = true
				this.checkForm.managementId = this.dataId
				postAction(this.checkBack, this.checkForm, 2).then(res => {
					if (res.success) {
						this.handleCheckPassWinClose()
						this.$emit('onBack')
					}
					this.backLoading = false
				})
			},
			passHandler() {
				this.checkForm.managementId = this.dataId
				this.showFlowSend = true
				this.checkFlowType = 3
				this.sendtype = 1
				this.instNodeId = this.checkData.wfInstNodeId
			},
			rejectHandler() {
				this.checkForm.managementId = this.dataId
				this.showFlowSend = true
				this.checkFlowType = 2
				this.sendtype = -1
				this.instNodeId = this.checkData.wfInstNodeId
			},
			flowCallback() {
				this.handleCheckPassWinClose()
				this.$message.success('操作成功！')
				this.$emit('onPass')
			},
		},
	}
</script>
<style lang="scss" scoped>
	.dialog {
		/deep/.el-dialog__body {
			padding: 0 20px 30px 20px;
		}

		/deep/.el-dialog__footer {
			padding: 0 !important;
		}
	}

	.dialog-footer {
		border-top: 1px solid #f0f0f0;
		display: flex;
		justify-content: flex-end;
		padding: 10px 15px;
	}
</style>
